<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<title>添加文章</title>
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<link rel="stylesheet" href="/public/static/admin/css/oksub.css">
<!--	<script type="text/javascript" src="/public/static/admin/lib/loading/okLoading.js"></script>-->
</head>
<body>
<div class="ok-body">
	<!--form表单-->
	<form class="layui-form layui-form-pane ok-form">
		<div class="layui-form-item">
			<label class="layui-form-label">网站名称</label>
			<div class="layui-input-block">
				<input type="text" name="title" placeholder="请输入网站名称" autocomplete="off" class="layui-input"
				       lay-verify="required" value="{$webset['webset_name']}">
			</div>
		</div>
<!--		<div class="layui-form-item">-->
<!--			<label class="layui-form-label">分类</label>-->
<!--			<div class="layui-input-block">-->
<!--				<select name="classify">-->
<!--					<option value="0">公告</option>-->
<!--					<option value="1">言情</option>-->
<!--					<option value="2">都市</option>-->
<!--					<option value="3">修仙</option>-->
<!--				</select>-->
<!--			</div>
		</div>-->
		<div class="layui-form-item">
			<label class="layui-form-label">联系电话</label>
			<div class="layui-input-block">
				<input type="text" name="phone" placeholder="请输入联系电话" autocomplete="off" class="layui-input"
				       lay-verify="required" value="{$webset['webset_phone']}">
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label">400电话</label>
			<div class="layui-input-block">
				<input type="text" name="4phone" placeholder="请输入400电话" autocomplete="off" class="layui-input"
					   lay-verify="required" value="{$webset['webset_4phone']}">
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label">底部版权</label>
			<div class="layui-input-block">
				<input type="text" name="copy" placeholder="请输入版权信息" autocomplete="off" class="layui-input"
					   lay-verify="required" value="{$webset['webset_copy']}">
			</div>
		</div>
					<input hidden="hidden" id="id" value="{$webset['Id']}">
<!--		<div class="layui-form-item">-->
<!--			<label class="layui-form-label">状态</label>-->
<!--			<div class="layui-input-block">-->
<!--				<input type="checkbox" name="status" lay-skin="switch" lay-text="启用|停用" checked value="0">-->
<!--				<input type="hidden" id="text1" name="text1" value="0000" >-->
<!--			</div>-->
<!--		</div>-->
<!--		<div class="layui-form-item">-->
<!--			<label class="layui-form-label">置顶</label>-->
<!--			<div class="layui-input-block">-->
<!--				<input type="checkbox" name="isTop" lay-skin="switch" lay-text="是|否" value="0">-->
<!--			</div>-->
<!--		</div>-->




		<button type="button" class="layui-btn" id="cover">
			<i class="layui-icon">&#xe67c;</i>上传logo
		</button>
		<img id="preview" name="preview" width="20%" height="20%" src="{$webset['webset_logo']}">
		<input type="text" hidden="hidden"  value="" name="imagesrc" id="imagesrc1"/>

<!--		<div class="layui-form-item layui-form-text">-->
<!--			<label class="layui-form-label">摘要</label>-->
<!--			<div class="layui-input-block">-->
<!--				<textarea name="des" placeholder="请输入文章内容" class="layui-textarea" lay-verify="required"></textarea>-->
<!--			</div>-->
<!--		</div>-->
<!--		<div class="layui-form-item layui-form-text">-->
<!--			<label class="layui-form-label">内容</label>-->
<!--			<div id="editor">-->
<!--			</div>-->
<!--			<br/>-->
<!--		</div>-->
		<!--js逻辑-->
		<script src="/public/static/admin/lib/wangEditor/release/wangEditor.min.js"></script>
		<script type="text/javascript">
			let E = window.wangEditor;
			let editor = new E("#editor");
			var text1=document.getElementById('text1');
			editor.customConfig.uploadImgShowBase64 = true   // 使用 base64 保存图片

			editor.customConfig.onchange=function(html){
				text1.setAttribute('value',editor.txt.html());
			}
			editor.customConfig.uploadImgServer = '../../admin/Often/editUploads'; //上传URL
			editor.customConfig.uploadImgMaxLength = 100;
			editor.customConfig.uploadImgMaxSize = 2 * 600 * 600;
			editor.customConfig.uploadFileName = 'file';//服务端接收file的名字
			editor.customConfig.uploadImgHooks = {
				customInsert: function (insertImg, result, editor) {
					// 图片上传并返回结果，自定义插入图片的事件（而不是编辑器自动插入图片！！！）
					// insertImg 是插入图片的函数，editor 是编辑器对象，result 是服务器端返回的结果
					console.log(result);
					// 举例：假如上传图片成功后，服务器端返回的是 {url:'....'} 这种格式，即可这样插入图片：
					var url =result.data;
					insertImg(url);

					// result 必须是一个 JSON 格式字符串！！！否则报错
				}
			}
			editor.customConfig.debug = true;
			editor.create();




		</script>

		<div class="layui-form-item">
			<div class="layui-input-block">
				<button class="layui-btn" lay-submit lay-filter="addArticle">立即提交</button>
				<button type="reset" class="layui-btn layui-btn-primary">重置</button>
			</div>
		</div>
	</form>
</div>
<!--js逻辑-->
<script src="/public/static/admin/lib/layui/layui.js"></script>

<script>
	layui.use(["form", "okUtils", "okLayer"], function () {
		let form = layui.form;
		let okUtils = layui.okUtils;
		let okLayer = layui.okLayer;
		let okMock = layui.okMock;
		// okLoading.close();
		form.on("submit(addArticle)", function (data) {

			okUtils.ajax("webset/upweb", "post", data.field, true).done(function (response) {
				okLayer.greenTickMsg(response.msg, function () {
					parent.layer.close(parent.layer.getFrameIndex(window.name));
				});
			}).fail(function (error) {
				console.log(error)
			});
			return false;
		});
	});


	layui.use('upload', function() {
		var upload = layui.upload;
		var $ = layui.jquery;
		var uploadInst = upload.render({
			elem:'#cover'
			,url:'../../admin/Often/upload'
			,accept:'file'  // 允许上传的文件类型
			,auto:true // 自动上传
			,before:function (obj) {
				console.log(obj);
				// 预览
				obj.preview(function(index,file,result) {
					// console.log(file.name);    //图片名字
					// console.log(file.type);    //图片格式
					// console.log(file.size);    //图片大小
					console.log(result);       //图片地址
					$('#preview').attr('src',result); //图片链接 base64
					$('#imagesrc1').attr('value',result);
				});
				// layer.load();
			}
			// 上传成功回调
			,done:function(res) {
				// console.log(upload);

				$('#imagesrc1').attr('value',res['url']);
				if (res.code == 0) {
					return layer.msg(res.msg);
				}
				return layer.msg(res.msg);
			}
			// 上传失败回调
			,error:function(index,upload) {
				return layer.msg(res.msg);
			}

		});
	});



</script>
</body>
</html>
